/*
* @作者：王云龙
* @日期：2017/3/30
* @功能：传入mp3声音文件，可以实现播放和停止功能，兼容ie
* 
* */

function esayTips(sound){
	
	this.options = {
		id : 'tips_sound',
		soundFile : sound
	};
	
	this.createEl();
}

//在页面上加上播放声音的标签

esayTips.prototype.createEl = function(){
	
	var borswer = window.navigator.userAgent.toLowerCase();
	var options = this.options;
	if ( this.isIe() )
	{
		//兼容ie
		var strAudio = '<bgsound id="'+options.id+'" name="embedPlay" src="" hidden="true" loop="-1"></bgsound>';
	}else{
		//非ie浏览器
		var strAudio = '<audio id="'+options.id+'" autoplay="autoplay" src="" hidden="true" loop="true">';
	}
	
	$("body").append(strAudio);
	
	this.tips = document.getElementById(options.id);
}

//判断浏览器是否为ie

esayTips.prototype.isIe = function(){
	if (!!window.ActiveXObject || "ActiveXObject" in window)
  	return true;
  	else
  	return false;
}

//播放声音

esayTips.prototype.play = function(){
	var options = this.options;
	this.tips.setAttribute('src', options.soundFile);
	if(this.tips.play)
	this.tips.play();
}

//停止声音

esayTips.prototype.stop = function(){
	var options = this.options;
	this.tips.removeAttribute('src');
	if(this.tips.pause)
	this.tips.pause();
}
